package com.ylsk.check.task;

import com.ylsk.check.domain.CheckTask;
import com.ylsk.check.domain.emum.BasicInfoTemplateEnum;
import com.ylsk.check.domain.emum.ConstructionStatusEnum;
import com.ylsk.check.domain.vo.JeevesReportVO;
import com.ylsk.check.mapper.CheckTaskMapper;
import com.ylsk.check.mapper.JeevesReportMapper;
import com.ylsk.common.config.SnowIdConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * 自动生成检查单（占道上报数据)
 */
@Component("autoCreateCheckTask")
public class AutoCreateCheckTask {

    @Autowired
    private JeevesReportMapper jeevesReportMapper;

    @Autowired
    private SnowIdConfig snowIdConfig;

    @Autowired
    CheckTaskMapper checkTaskMapper;

    /**
     * 更新施工状态
     */
    public void jeevesReportCheckTask(){

        //  施工状态变更
        List<JeevesReportVO> jeevesReportVOList = jeevesReportMapper.autoCreateCheckTask(null);

        if(!CollectionUtils.isEmpty(jeevesReportVOList)){
            for (JeevesReportVO jeevesReportVO : jeevesReportVOList) {
                Long reportInfoId = jeevesReportVO.getReportInfoId();
                Long jeevesReportId = jeevesReportVO.getJeevesReportId();
                Long deptId = jeevesReportVO.getDeptId();
                Long createBy = jeevesReportVO.getCreateBy();


                CheckTask checkTask = new CheckTask();
                checkTask.setCheckTaskId(snowIdConfig.getSnowId());
                checkTask.setReportInfoId(reportInfoId);
                checkTask.setConstructionStatus(ConstructionStatusEnum.ROAD_CONSTRUCTION.getCode());
                checkTask.setTbName(BasicInfoTemplateEnum.INS_JEEVES_REPORT.getTbName());
                checkTask.setReportBusinessId(jeevesReportId);
                checkTask.setExecTime(new Date());
                checkTask.setDeptId(deptId);
                checkTask.setTaskStatus(0);//任务状态未检查
                checkTask.setCreateBy(createBy);
                checkTask.setUpdateBy(createBy);
                checkTaskMapper.insert(checkTask);
            }
        }

    }
}
